﻿using System;
using System.Web.Configuration;
using System.Collections.Generic;
using System.Data.SqlClient;
using log4net;

namespace TheBullysStore.Models.ModuloAdministracion.Banco
{
    public class BancoDAO
    {
        public static String cadenaDB = WebConfigurationManager.ConnectionStrings["TheBullysStore"].ConnectionString;
        private static ILog log = LogManager.GetLogger(typeof(BancoDAO));

        public List<BancoBean> ListarBanco(BancoBean banco)
        {
            SqlConnection sqlCon = null;
            try
            {
                List<BancoBean> listaBanco = new List<BancoBean>();

                sqlCon = new SqlConnection(cadenaDB);

                sqlCon.Open();

                string commandString = "SELECT * FROM Banco WHERE estado = 1";

                SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon);

                SqlDataReader dataReader = sqlCmd.ExecuteReader();

                while (dataReader.Read())
                {
                    BancoBean Banco = new BancoBean();
                    Banco.NombreComercial = Convert.ToString(dataReader["NombreComercial"]);
                    Banco.RazonSocial = Convert.ToString(dataReader["RazonSocial"]);
                    Banco.Estado = Convert.ToInt32(dataReader["Estado"]);
                    Banco.IdBanco = Convert.ToInt32(dataReader["Id_Banco"]);
                    listaBanco.Add(Banco);
                }
                dataReader.Close();                

                return listaBanco;
            }
            catch (Exception ex)
            {
                log.Error("listarBanco(EXCEPTION): ", ex);
                throw ex;
            }
            finally {
                sqlCon.Close();
            }
        }
    }
}